import java.util.HashSet;
import java.util.Set;

public class Solution {
    //最长无重复字串
    public int lengthOfLongestSubstring(String s) {
        //以i位置单词开始最长的无重复字串长度
        if(s.length() == 0) {
            return 0;
        }
        int max_length = 1;
        for(int i = 0; i < s.length(); i++) {
            Set<Character> set = new HashSet<>();
            char left = s.charAt(i);
            set.add(left);
            int right = i+1;
            int count = 1;
            while(right < s.length()) {
                if(s.charAt(right) != left && !set.contains(s.charAt(right))) {
                    set.add(s.charAt(right));
                    right++;
                    count++;
                }else{
                    break;
                }
            }
            max_length = Math.max(max_length,count);
        }
        return max_length;
    }
}
